//! TODO: 更新数据库. 目前使用的OpenCC的数据, 不全面.

mod trans_map;

use std::sync::LazyLock;

static S2T_TRANSLATOR: LazyLock<trans_map::WordTranslator> = LazyLock::new(|| {
    trans_map::WordTranslator::with_map_file_paths("STPhrases.txt", "STCharacters.txt")
});
static T2S_TRANSLATOR: LazyLock<trans_map::WordTranslator> = LazyLock::new(|| {
    trans_map::WordTranslator::with_map_file_paths("TSPhrases.txt", "TSCharacters.txt")
});

pub fn converter(input: &str, tp: &str) -> String {
    println!("Input: {input}, tp: {tp}");
    let trans_type = TransType::convert_from_str(tp);
    let translator = match trans_type {
        TransType::S2T => &S2T_TRANSLATOR,
        TransType::T2S => &T2S_TRANSLATOR,
    };

    let res = translator.trans(input);
    println!("Result: {res}");
    res
}

enum TransType {
    S2T,
    T2S,
}

impl TransType {
    pub fn convert_from_str(s: &str) -> TransType {
        match s {
            "s2t" => TransType::S2T,
            "t2s" => TransType::T2S,
            _ => {
                panic!("Unknown translation type: {s}");
            }
        }
    }
}
